"use strict";
cc._RF.push(module, '72b00qDoNZKyKSQzZvK3DvF', 'level_goldMiner');
// scripts/levelBundles/level_goldMiner/level_goldMiner.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var LevelBase_1 = require("../../Game/Base/LevelBase");
var Enum_1 = require("../../Game/Enum");
var MainRoot_1 = require("../../Game/MainRoot");
var gameEngine_1 = require("../../engines/gameEngine");
var CsvFileKind_1 = require("../../engines/libs/CsvFileKind");
var data_control_1 = require("../../engines/libs/data_control");
var physics_tool_1 = require("../../engines/libs/physics_tool");
var level_goldMiner_goodsBase_1 = require("./base/level_goldMiner_goodsBase");
var goldMinerConst_1 = require("./const/goldMinerConst");
var level_goldMiner_landmark_1 = require("./other/level_goldMiner_landmark");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level_goldMiner = /** @class */ (function (_super) {
    __extends(level_goldMiner, _super);
    function level_goldMiner() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.hookNode = null;
        _this.hookAniNode = null;
        _this.touchNode = null;
        _this.gameArea = null;
        _this.mapArea = null;
        _this.roleNode = null;
        _this.roleKhan = null;
        _this.ropeShakeAni = null;
        _this.merchant = null;
        _this.merchantChatNode = null;
        _this.lbChat = null;
        _this.lbMoney = null;
        _this.lbShow = null;
        _this.cameraNode = null;
        _this.cameraTargetNode = null;
        _this.boomLayout = null;
        _this.boomItem = null;
        /** 0 静止 1左摆 2右摆 3往前伸 4 往后拉*/
        _this.hookState = goldMinerConst_1.hookState.idle;
        /**钩子是否旋转 */
        _this.hookRotationFlag = false;
        /**钩子旋转速度 */
        _this.hookAngularVelocity = 0;
        /**钩子最大旋转角度 */
        _this.hookMaxAngle = 75;
        /**钩子减速角度 */
        _this.hookRetardAngle = 50;
        /**钩子最大速度 */
        _this.hookMaxAngularVelocity = 2.25 * 60;
        /**钩子最小速度 */
        _this.hookMinAngularVelocity = 0.1 * 60;
        /**当前勾中的物品 */
        _this.curGoods = null;
        /**游戏是否暂停 */
        _this.gamePauseFlag = true;
        /**钩子伸出速度 */
        _this.hookStretchSpeed = 500;
        /**钩子勾空拉回速度 */
        _this.hookNullSpeed = 1000;
        /**游戏进度 */
        _this.gameStep = 0;
        /**当前的钱 */
        _this.curMoney = 0;
        /**目标需要的钱 */
        _this.targetMoney = 0;
        /**当前阶段倒计时 */
        _this.curCountDown = 0;
        /**切换状态之前的最后一个旋转状态 */
        _this.lastHookState = goldMinerConst_1.hookState.idle;
        _this.targetMoneyAry = [];
        _this.coutDownAry = [];
        _this.levelData = null;
        _this.inGamePage = null;
        _this.canTouch = false;
        _this.hasClean = false;
        _this.ropeInitHeight = 0;
        return _this;
    }
    level_goldMiner.prototype.Init = function (info) {
        return __awaiter(this, void 0, Promise, function () {
            var inGamePrams, page;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.levelInfo = info;
                        this.m_mode = info.mode;
                        this.tips = info.tips;
                        inGamePrams = {
                            mode: this.m_mode,
                            levelInfo: this.levelInfo,
                            title: info.title,
                            tips: info.tips,
                            hideTitle: info.hideTitle
                        };
                        gameEngine_1.default.getManagers().soundMgr.loadSoundBundle("goldMinerSound");
                        gameEngine_1.default.on(Enum_1.GAME_EVENT.ON_BTN_TIPS, this.OnTips.bind(this));
                        this.levelData = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.goldMinerLevel, this.levelInfo.level);
                        this.targetMoneyAry = this.levelData["turn_target"].split("|").map(function (v) { return Number(v); });
                        this.coutDownAry = this.levelData["turn_time"].split("|").map(function (v) { return Number(v); });
                        return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.GOLD_MINER_INGAME_PAGE, inGamePrams)];
                    case 1:
                        page = _a.sent();
                        this.hookStretchSpeed = Number(this.levelData["hook_stretch_speed"]);
                        this.hookNullSpeed = Number(this.levelData["hook_null_speed"]);
                        this.inGamePage = page;
                        this.inGamePage.bindLevel(this);
                        this.ropeInitHeight = this.hookNode.getChildByName("rope").height;
                        this.refrenshBoomLayout();
                        return [4 /*yield*/, this.loadGame()];
                    case 2:
                        _a.sent();
                        this.touchNodeAddEvent();
                        this.hookState = goldMinerConst_1.hookState.left;
                        this.lastHookState = goldMinerConst_1.hookState.left;
                        this.gameResume();
                        physics_tool_1.default.openCollision();
                        return [2 /*return*/];
                }
            });
        });
    };
    level_goldMiner.prototype.start = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                this.cameraNode = gameEngine_1.default.Canvas().getChildByName("Main Camera");
                gameEngine_1.default.on("refrenshBoom", this.refrenshBoomLayout, this);
                return [2 /*return*/];
            });
        });
    };
    level_goldMiner.prototype.startHook = function () {
        this.hookRotationFlag = true;
    };
    level_goldMiner.prototype.stopHook = function () {
        this.hookRotationFlag = false;
    };
    level_goldMiner.prototype.hookAni = function () {
        var needTime = 1;
        cc.tween(this.hookNode).to(needTime, { angle: -75 }, { easing: cc.easing.backOut }).to(needTime, { angle: 0 }, { easing: cc.easing.backIn }).start();
    };
    level_goldMiner.prototype.loadGame = function () {
        return __awaiter(this, void 0, void 0, function () {
            var needCounts, curCount;
            var _this = this;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.gameArea.destroyAllChildren();
                        needCounts = this.mapArea.children[this.gameStep].childrenCount;
                        this.targetMoney = this.targetMoneyAry[this.gameStep];
                        this.curCountDown = this.coutDownAry[this.gameStep];
                        curCount = 0;
                        this.inGamePage.refrenshTime();
                        this.refrenshCurMoney();
                        this.inGamePage.refrenshStep();
                        return [4 /*yield*/, new Promise(function (resolve) {
                                if (needCounts == 0) {
                                    resolve();
                                    return;
                                }
                                _this.mapArea.children[_this.gameStep].children.forEach(function (n) {
                                    var ns = n.getComponent(level_goldMiner_landmark_1.default);
                                    var nid = ns.getObjId();
                                    var data = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.goldMinerHoookGooods, nid);
                                    var prefabPath = data["prefab_path"];
                                    MainRoot_1.default.LevelSystem.getOneTypeBundle(_this.getLevelInfo().levelType).load("level_abb_goldMiner/" + prefabPath, cc.Prefab, function (err, prefab) {
                                        if (err) {
                                            console.log(err, "加载物品失败");
                                            return;
                                        }
                                        var node = cc.instantiate(prefab);
                                        var ns = node.getComponent(level_goldMiner_goodsBase_1.default);
                                        ns.bindData(data);
                                        var pos = _this.gameArea.convertToNodeSpaceAR(n.convertToWorldSpaceAR(cc.v2()));
                                        node.parent = _this.gameArea;
                                        node.setPosition(pos);
                                        curCount++;
                                        if (curCount == needCounts) {
                                            resolve();
                                        }
                                    });
                                });
                            })];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, this.inGamePage.showTargetNode(this.targetMoney)];
                    case 2:
                        _a.sent();
                        this.refrenshCurMoney();
                        this.canTouch = true;
                        this.schedule(this.subCountDown, 1);
                        return [2 /*return*/];
                }
            });
        });
    };
    level_goldMiner.prototype.update = function (dt) {
        var _this = this;
        if (this.gamePauseFlag) {
            return;
        }
        var subAngle = this.hookMaxAngularVelocity * dt;
        var angle = this.hookMaxAngle - this.hookRetardAngle;
        var ratio = (Math.abs(this.hookNode.angle) - Math.abs(this.hookRetardAngle)) / angle;
        var addition = gameEngine_1.default.getManagers().goldMinerManager.getAdditionByLevel();
        switch (this.hookState) {
            case goldMinerConst_1.hookState.idle: {
                break;
            }
            case goldMinerConst_1.hookState.left: {
                if (this.hookNode.angle <= -this.hookRetardAngle) {
                    subAngle = (this.hookMaxAngularVelocity * dt) - (ratio * this.hookMaxAngularVelocity) * dt;
                    subAngle = Math.max(subAngle, this.hookMinAngularVelocity * dt);
                }
                this.hookNode.angle -= subAngle;
                if (this.hookNode.angle <= -this.hookMaxAngle) {
                    this.hookState = goldMinerConst_1.hookState.right;
                    this.lastHookState = goldMinerConst_1.hookState.right;
                }
                break;
            }
            case goldMinerConst_1.hookState.right: {
                if (this.hookNode.angle >= this.hookRetardAngle) {
                    subAngle = (this.hookMaxAngularVelocity * dt) - (ratio * this.hookMaxAngularVelocity * dt);
                    subAngle = Math.max(subAngle, this.hookMinAngularVelocity * dt);
                }
                this.hookNode.angle += subAngle;
                // this.hookNode.angle -= this.hookMaxAngularVelocity;
                if (this.hookNode.angle >= this.hookMaxAngle) {
                    this.hookState = goldMinerConst_1.hookState.left;
                    this.lastHookState = goldMinerConst_1.hookState.left;
                }
                break;
            }
            case goldMinerConst_1.hookState.stretch: {
                var rope = this.hookNode.getChildByName("rope");
                var hook = rope.getChildByName("hook");
                rope.height += (this.hookStretchSpeed + this.hookStretchSpeed * addition) * dt;
                if (!hook.getBoundingBoxToWorld().intersects(this.touchNode.getBoundingBoxToWorld())) {
                    this.hookState = goldMinerConst_1.hookState.pullBack;
                }
                break;
            }
            case goldMinerConst_1.hookState.pullBack: {
                var rope = this.hookNode.getChildByName("rope");
                var speed = this.hookNullSpeed;
                if (this.curGoods && this.curGoods.isValid) {
                    speed = Number(this.curGoods.getComponent(level_goldMiner_goodsBase_1.default).data["return_speed"]) + (Number(this.curGoods.getComponent(level_goldMiner_goodsBase_1.default).data["return_speed"]) * addition);
                }
                else {
                    speed = this.hookNullSpeed + (this.hookNullSpeed * addition);
                }
                var curHeight = speed * dt;
                if (rope.height - curHeight < this.ropeInitHeight) {
                    curHeight = rope.height - this.ropeInitHeight;
                }
                rope.height -= curHeight;
                if (rope.height <= this.ropeInitHeight) {
                    this.ropeShakeAni.node.active = false;
                    this.hookState = this.lastHookState;
                    this.peopleStopKhan();
                    this.roleNode.getComponent(cc.Animation).play("idle");
                    this.hookAniNode.getComponent(cc.Animation).play("idle");
                    if (this.curCountDown <= 0) {
                        this.canTouch = false;
                    }
                    this.recycleObj().then(function () {
                        if (_this.curCountDown <= 0) {
                            _this.checkGame();
                        }
                        else if (_this.gameArea.childrenCount <= 0) {
                            _this.checkGame();
                        }
                    });
                }
                break;
            }
        }
    };
    level_goldMiner.prototype.recycleObj = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                if (this.curGoods) {
                    this.hasClean = true;
                    return [2 /*return*/, new Promise(function (resolve) {
                            var node = _this.curGoods;
                            var pos = _this.node.convertToNodeSpaceAR(node.convertToWorldSpaceAR(cc.v2()));
                            node.setParent(_this.node);
                            node.setPosition(pos);
                            _this.curGoods = null;
                            var cs = node.getComponent(level_goldMiner_goodsBase_1.default);
                            var cData = cs.data;
                            var minMoney = Number(cData["min_price"]);
                            var maxMoney = Number(cData["max_price"]);
                            var realMoney = Math.floor(data_control_1.default.getRandNumberOfArrayTwo([minMoney, maxMoney]));
                            var oneRealMoney = realMoney;
                            var cType = cData["good_classification"];
                            switch (cType) {
                                case "2": {
                                    realMoney = realMoney + realMoney * gameEngine_1.default.getManagers().goldMinerManager.diamondPrice;
                                    break;
                                }
                                case "4": {
                                    realMoney = realMoney + realMoney * gameEngine_1.default.getManagers().goldMinerManager.boxPrice;
                                    break;
                                }
                                case "6": {
                                    gameEngine_1.default.getManagers().goldMinerManager.setData({ hookLevel: 1 }, true);
                                    _this.showSpeedUpgrade();
                                    break;
                                }
                            }
                            realMoney = Math.floor(realMoney + oneRealMoney * gameEngine_1.default.getManagers().goldMinerManager.allPrice);
                            var targetPos = _this.node.convertToNodeSpaceAR(_this.roleNode.convertToWorldSpaceAR(cc.v2()));
                            // let converPos:cc.Vec2 = this.gameArea.convertToNodeSpaceAR(node.convertToWorldSpaceAR(cc.v2()));
                            // node.setParent(this.gameArea);
                            // node.setPosition(converPos);
                            // console.log(this.gameArea.getPosition(),">>>>>>>>>>",targetPos,"targetPos")
                            //@ts-ignore
                            cc.tween(node).to(0.2, { position: targetPos }).to(0.5, { opacity: 0 }).call(function () {
                                if (realMoney > 0) {
                                    _this.addMoney(realMoney);
                                }
                                _this.hasClean = false;
                                resolve();
                                node.destroy();
                                node.removeFromParent();
                            }).start();
                            // let tween = cc.tween(node).delay(0.3).to(0,{opacity:0}).delay(0.3).to(0,{opacity:255});
                            // cc.tween(node).repeat(2,tween).call(()=>{
                            // }).start();
                        })];
                }
                return [2 /*return*/];
            });
        });
    };
    level_goldMiner.prototype.touchNodeAddEvent = function () {
        this.touchNode.on("touchend", this.onTouchEndNode, this);
    };
    level_goldMiner.prototype.onTouchEndNode = function (e) {
        var _this = this;
        if (this.gamePauseFlag) {
            return;
        }
        if (!this.canTouch) {
            return;
        }
        if (this.hookState == goldMinerConst_1.hookState.left || this.hookState == goldMinerConst_1.hookState.right) {
            //切换成前伸 钩子飞出
            this.roleNode.getComponent(cc.Animation).play("ani");
            this.hookState = goldMinerConst_1.hookState.stretch;
        }
        else if (this.hookState == goldMinerConst_1.hookState.pullBack) {
            // 回收状态点击钩子 如果有炸弹道具则直接使用炸弹道具 如果没有则无需操作 等待拉伸结束即可
            if (gameEngine_1.default.getManagers().goldMinerManager.boomNum > 0 && this.curGoods) {
                gameEngine_1.default.getManagers().goldMinerManager.useBoom();
                var node_1 = this.curGoods;
                var pos = this.gameArea.convertToNodeSpaceAR(node_1.convertToWorldSpaceAR(cc.v2()));
                node_1.parent = this.gameArea;
                node_1.setPosition(pos);
                var boomItem_1 = this.boomLayout.children[gameEngine_1.default.getManagers().goldMinerManager.boomNum];
                var boomPos = this.gameArea.convertToNodeSpaceAR(boomItem_1.convertToWorldSpaceAR(cc.v2()));
                boomItem_1.setParent(this.gameArea);
                boomItem_1.setPosition(boomPos);
                this.refrenshBoomLayout();
                var ani_1 = boomItem_1.getComponent(cc.Animation);
                ani_1.play("Throw");
                //@ts-ignore
                cc.tween(boomItem_1).to(0.2, { position: pos, angle: 360 }).call(function () {
                    gameEngine_1.default.getManagers().soundMgr.playSound("goldMinerSound/boom");
                    ani_1.play("Boom");
                    ani_1.on('finished', function () {
                        boomItem_1.destroy();
                        boomItem_1.removeFromParent();
                    }, _this);
                    node_1.destroy();
                    node_1.removeFromParent();
                    // ani.on('')
                }).start();
                // this.curGoods.destroy();
                // this.curGoods.removeFromParent();
                this.curGoods = null;
            }
        }
    };
    /**
     * 碰撞
     * @param oneColider
     * @param twoColider
     */
    level_goldMiner.prototype.onColision = function (oneColider, twoColider) {
        var os = oneColider.node.getComponent(level_goldMiner_goodsBase_1.default);
        if (oneColider.tag == goldMinerConst_1.goldMinerTag.goods && twoColider.tag == goldMinerConst_1.goldMinerTag.hoook && !this.curGoods && !os.pullBackFlag && this.hookState == goldMinerConst_1.hookState.stretch) {
            // 钩子碰到了物品
            gameEngine_1.default.getManagers().soundMgr.playSound("goldMinerSound/sound");
            this.curGoods = oneColider.node;
            var objLayout = this.hookNode.getChildByName("rope").getChildByName("hook").getChildByName("objLayout");
            this.ropeShakeAni.node.active = true;
            this.ropeShakeAni.play();
            var cs = this.curGoods.getComponent(level_goldMiner_goodsBase_1.default);
            cs.toPullBack();
            var chatType = cs.data["chat_type"];
            var objId = cs.data["objId"];
            if (Math.random() < Number(this.levelData["obj_chat_pro"])) {
                this.showOneChat(chatType, objId);
            }
            this.curGoods.setParent(objLayout);
            this.curGoods.setPosition(0, -10 - this.curGoods.height / 2);
            this.hookState = goldMinerConst_1.hookState.pullBack;
            this.hookAniNode.getComponent(cc.Animation).play("ani");
            this.peopleStartKhan();
        }
    };
    /**游戏暂停 */
    level_goldMiner.prototype.gamePause = function () {
        this.gamePauseFlag = true;
    };
    /**游戏继续 */
    level_goldMiner.prototype.gameResume = function () {
        this.gamePauseFlag = false;
    };
    level_goldMiner.prototype.addMoney = function (money) {
        this.curMoney += money;
        var node = cc.instantiate(this.lbShow);
        var label = node.getComponent(cc.Label);
        label.string = "+" + money;
        var pos = this.node.convertToNodeSpaceAR(this.roleNode.convertToWorldSpaceAR(cc.v2()));
        pos.y += 120;
        node.setParent(this.node);
        node.setPosition(pos);
        node.scale = 0.5;
        cc.tween(node).by(0.2, { y: 50, scale: 0.5 }).delay(1).call(function () {
            node.destroy();
            node.removeFromParent();
        }).start();
        this.refrenshCurMoney();
    };
    level_goldMiner.prototype.refrenshCurMoney = function () {
        this.lbMoney.string = data_control_1.default.getNumberFormat(this.curMoney) + "/" + data_control_1.default.getNumberFormat(this.targetMoney);
    };
    level_goldMiner.prototype.subCountDown = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                if (this.gamePauseFlag) {
                    return [2 /*return*/];
                }
                this.curCountDown--;
                this.curCountDown = Math.max(0, this.curCountDown);
                this.inGamePage.refrenshTime();
                if (this.curCountDown <= 0) {
                    // 判断是否达到了目标 如果没达到则判断失败
                    this.checkGame();
                }
                return [2 /*return*/];
            });
        });
    };
    level_goldMiner.prototype.checkGame = function () {
        console.log("checkGame");
        if (this.hookState != goldMinerConst_1.hookState.pullBack && this.hookState != goldMinerConst_1.hookState.stretch && !this.hasClean) {
            if (this.curMoney >= this.targetMoney) {
                this.gameStep++;
                if (this.gameStep >= this.targetMoneyAry.length) {
                    this.Win(2);
                    this.unschedule(this.subCountDown);
                }
                else {
                    this.stepEnd();
                    this.unschedule(this.subCountDown);
                }
            }
            else {
                this.Lose(2);
                this.unschedule(this.subCountDown);
            }
        }
    };
    level_goldMiner.prototype.stepEnd = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        this.canTouch = false;
                        gameEngine_1.default.getManagers().soundMgr.playSound("goldMinerSound/transition");
                        return [4 /*yield*/, this.cameraAni(true)];
                    case 1:
                        _a.sent();
                        return [4 /*yield*/, this.showOneChat("3", null, 3)];
                    case 2:
                        _a.sent();
                        gameEngine_1.default.getManagers().goldMinerManager.resetProp();
                        this.refrenshBoomLayout();
                        gameEngine_1.default.getManagers().soundMgr.playSound("goldMinerSound/store");
                        return [4 /*yield*/, this.showShopPage()];
                    case 3:
                        _a.sent();
                        return [4 /*yield*/, this.loadGame()];
                    case 4:
                        _a.sent();
                        return [4 /*yield*/, this.cameraAni(false)];
                    case 5:
                        _a.sent();
                        return [2 /*return*/];
                }
            });
        });
    };
    level_goldMiner.prototype.showShopPage = function () {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
                        var page, p;
                        return __generator(this, function (_a) {
                            switch (_a.label) {
                                case 0: return [4 /*yield*/, MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.LEVEL_GOLD_MINER_SHOPPAGE)];
                                case 1:
                                    page = _a.sent();
                                    p = page;
                                    p.bindLevel(this, resolve);
                                    return [2 /*return*/];
                            }
                        });
                    }); })];
            });
        });
    };
    level_goldMiner.prototype.cameraAni = function (endFlag) {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve) {
                        if (endFlag) {
                            //@ts-ignore
                            cc.tween(_this.cameraNode).to(1, { position: _this.cameraTargetNode.getPosition() }).start();
                            cc.tween(_this.cameraNode.getComponent(cc.Camera)).to(1, { zoomRatio: 1.5 }).call(resolve).start();
                        }
                        else {
                            cc.tween(_this.cameraNode).to(1, { position: cc.v3(0, 0, 0) }).start();
                            cc.tween(_this.cameraNode.getComponent(cc.Camera)).to(1, { zoomRatio: 1 }).call(resolve).start();
                        }
                    })];
            });
        });
    };
    /**
     * 商人展示某一种类型的对话
     * @param type 类型
     * @param objId 物品id
     */
    level_goldMiner.prototype.showOneChat = function (type, objId, autoHideTime) {
        var _this = this;
        if (autoHideTime === void 0) { autoHideTime = 5; }
        return new Promise(function (resolve) {
            _this.merchant.getComponent(cc.Animation).play("ani");
            var chats = _this.getOneTypeChats(type, objId);
            var chat = data_control_1.default.getRandItemOfArray(chats);
            _this.lbChat.string = chat["chat_desc"];
            cc.Tween.stopAllByTarget(_this.merchantChatNode);
            cc.tween(_this.merchantChatNode).to(0.2, { scale: 1 }, { easing: cc.easing.backOut }).delay(autoHideTime).call(function () {
                _this.hideOneChat();
                _this.merchant.getComponent(cc.Animation).play("idle");
                resolve();
            }).start();
        });
    };
    level_goldMiner.prototype.hideOneChat = function () {
        cc.tween(this.merchantChatNode).to(0.2, { scale: 0 }, { easing: cc.easing.backIn }).start();
    };
    level_goldMiner.prototype.getOneTypeChats = function (type, objId) {
        var allChat = gameEngine_1.default.getManagers().csvDataManager.getCsvIds(CsvFileKind_1.CsvFileKind.CsvFile.goldMinerChats);
        var chatAry = [];
        var commonAry = [];
        for (var _i = 0, allChat_1 = allChat; _i < allChat_1.length; _i++) {
            var id = allChat_1[_i];
            var chat = gameEngine_1.default.getManagers().csvDataManager.getCsvDataItem(CsvFileKind_1.CsvFileKind.CsvFile.goldMinerChats, id);
            if (chat["type"] == type) {
                chatAry.push(chat);
            }
            if (chat["objId"] == objId && chat["type"] == type) {
                commonAry.push(chat);
            }
        }
        if (commonAry.length > 0) {
            return commonAry;
        }
        else {
            return chatAry;
        }
    };
    level_goldMiner.prototype.targetLbAni = function () {
        var tween = cc.tween(this.lbMoney.node).delay(0.1).to(0, { color: cc.Color.RED }).delay(0.1).to(0, { color: cc.color(57, 17, 2) });
        cc.tween(this.lbMoney.node).repeat(3, tween).start();
    };
    level_goldMiner.prototype.refrenshBoomLayout = function () {
        var targetCount = gameEngine_1.default.getManagers().goldMinerManager.boomNum;
        var nowCount = this.boomLayout.childrenCount;
        var needCount = targetCount - nowCount;
        if (needCount > 0) {
            for (var i = 0; i < needCount; i++) {
                var node = cc.instantiate(this.boomItem);
                node.parent = this.boomLayout;
                var ani = node.getComponent(cc.Animation);
                ani.play("Idle");
            }
        }
    };
    level_goldMiner.prototype.peopleStartKhan = function () {
        var _this = this;
        this.roleKhan.y = 115;
        this.roleKhan.scale = 0.5;
        this.roleKhan.opacity = 0;
        var tween = cc.tween(this.roleKhan).call(function () {
            _this.roleKhan.opacity = 255;
        }).to(0.3, { y: 95, scale: 1 }).delay(0.2).call(function () {
            _this.roleKhan.opacity = 0;
            _this.roleKhan.scale = 0.5;
            _this.roleKhan.y = 115;
        }).delay(1);
        cc.tween(this.roleKhan).repeatForever(tween).start();
    };
    level_goldMiner.prototype.peopleStopKhan = function () {
        this.roleKhan.y = 115;
        this.roleKhan.scale = 0.5;
        this.roleKhan.opacity = 0;
        cc.Tween.stopAllByTarget(this.roleKhan);
    };
    level_goldMiner.prototype.Lose = function (time) {
        var _this = this;
        if (this.hadEnd) {
            return;
        }
        this.hadEnd = true;
        var delayTime = 2;
        if (time) {
            delayTime = time;
        }
        this.scheduleOnce(function () {
            gameEngine_1.managers().soundMgr.playSound('mainSound/inLevel');
            var losePrams = {
                mode: _this.m_mode,
                loseText: _this.levelInfo.loseText,
                tips: _this.levelInfo.tips,
                index: _this.levelInfo.level
            };
            MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.LOSEPAGE, losePrams);
        }, delayTime);
    };
    level_goldMiner.prototype.showSpeedUpgrade = function () {
        var node = cc.instantiate(this.lbShow);
        var label = node.getComponent(cc.Label);
        label.string = "\u901F\u5EA6\u63D0\u5347";
        node.color = cc.color(48, 255, 194);
        var pos = this.node.convertToNodeSpaceAR(this.roleNode.convertToWorldSpaceAR(cc.v2()));
        pos.y += 120;
        node.setParent(this.node);
        node.setPosition(pos);
        node.scale = 0.5;
        cc.tween(node).by(0.2, { y: 50, scale: 0.5 }).delay(1).call(function () {
            node.destroy();
            node.removeFromParent();
        }).start();
        this.refrenshCurMoney();
    };
    __decorate([
        property({ type: cc.Node, tooltip: "钩子节点" })
    ], level_goldMiner.prototype, "hookNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "钩子动画节点" })
    ], level_goldMiner.prototype, "hookAniNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "点击节点" })
    ], level_goldMiner.prototype, "touchNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "游戏区域" })
    ], level_goldMiner.prototype, "gameArea", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "地图区域" })
    ], level_goldMiner.prototype, "mapArea", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "角色节点" })
    ], level_goldMiner.prototype, "roleNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "角色汗珠" })
    ], level_goldMiner.prototype, "roleKhan", void 0);
    __decorate([
        property({ type: cc.Animation, tooltip: "绳子抖动动画" })
    ], level_goldMiner.prototype, "ropeShakeAni", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "商人节点" })
    ], level_goldMiner.prototype, "merchant", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "商人对话节点" })
    ], level_goldMiner.prototype, "merchantChatNode", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "商人对话文本" })
    ], level_goldMiner.prototype, "lbChat", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "钱文本" })
    ], level_goldMiner.prototype, "lbMoney", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "显示文本" })
    ], level_goldMiner.prototype, "lbShow", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "摄像机目标节点" })
    ], level_goldMiner.prototype, "cameraTargetNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "炸弹layout" })
    ], level_goldMiner.prototype, "boomLayout", void 0);
    __decorate([
        property({ type: cc.Prefab, tooltip: "炸弹节点" })
    ], level_goldMiner.prototype, "boomItem", void 0);
    level_goldMiner = __decorate([
        ccclass
    ], level_goldMiner);
    return level_goldMiner;
}(LevelBase_1.default));
exports.default = level_goldMiner;

cc._RF.pop();